package com.futures.investm.adapter;


import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.futures.investm.R;
import com.futures.investm.entity.MarketInfo;
import com.futures.investm.utils.IntentUtils;

import java.util.ArrayList;

/**
 * 外汇行情
 */
public class MarketForeignAdapter extends BaseQuickAdapter<MarketInfo, BaseViewHolder> {

    public MarketForeignAdapter() {
        super(R.layout.item_oil_market, new ArrayList<MarketInfo>());
    }

    @Override
    protected void convert(BaseViewHolder helper, final MarketInfo item) {

        Double dPC = Double.parseDouble(item.getPricechange()) * 100;

        helper.setText(R.id.tv_name, item.getName());
        helper.setText(R.id.tv_price, item.getLast());
        helper.setText(R.id.tv_percent, String.format("%.2f", dPC) + "%");


        if (Float.parseFloat(item.getPricechange()) > 0) {
            helper.setTextColor(R.id.tv_price, mContext.getResources().getColor(R.color.market_red));
            helper.setTextColor(R.id.tv_percent, mContext.getResources().getColor(R.color.market_red));
//            helper.setImageDrawable(R.id.img_line, mContext.getResources().getDrawable(R.mipmap.red));

        } else {
            helper.setTextColor(R.id.tv_price, mContext.getResources().getColor(R.color.market_blue));
            helper.setTextColor(R.id.tv_percent, mContext.getResources().getColor(R.color.market_blue));
//            helper.setImageDrawable(R.id.img_line, mContext.getResources().getDrawable(R.mipmap.blue));
        }


        String symbol = item.getSymbol();
        String strK = "";
        if (symbol.equals("BP")) {
            strK = "CMEGBP";
        } else if (symbol.equals("CD")) {
            strK = "";
        } else if (symbol.equals("DXF")) {
            strK = "CMEDX";
        } else if (symbol.equals("EC")) {
            strK = "CMEEC";
        } else if (symbol.equals("JY")) {
            strK = "CMEJY";
        } else if (symbol.equals("SF")) {
            strK = "";
        }

        final String finalStrK = strK;

        helper.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                IntentUtils.goMarketDetailsActivity(mContext, finalStrK, item.getName(), "1", item.getSymbol());
            }
        });
    }
}
